package com.zhdl.hardware.motor.buke.repository.impl;

import com.project.command.faq.event.behavior.BehaviorPerform;
import com.zhdl.hardware.motor.buke.repository.BukePortCmdHandleDao;
import com.zhdl.modules.tools.CommonCallback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@Component
public class BukePortCmdHandle implements BukePortCmdHandleDao {

    @Resource
    public BehaviorPerform behaviorPerform;
    public Map<String, BukeMotorCmdHandleDaoImpl> daoMap = new ConcurrentHashMap<>();


    public void addPort(String port){
        BukeMotorCmdHandleDaoImpl bukeMotorCmdHandleDao = new BukeMotorCmdHandleDaoImpl(port,behaviorPerform);
        daoMap.put(port,bukeMotorCmdHandleDao);
    }

    @Override
    public void bukeMotorRun(String port, String slaveId, Integer distance, Integer speed){
        daoMap.get(port).bukeMotorRun(slaveId,distance,speed);
    }
    @Override
    public void bukeMotorReady(String port, String slaveId){
        daoMap.get(port).bukeMotorReady(slaveId);
    }
    @Override
    public void bukeMotorNoReady(String port, String slaveId){
        daoMap.get(port).bukeMotorNoReady(slaveId);
    }
    @Override
    public void bukeGetStatus(String port, String slaveId, CommonCallback<String> callback){
        daoMap.get(port).bukeMotorStatus(slaveId,callback);
    }

}
